package day5;

import java.util.Scanner;
// https://www.nowcoder.com/practice/03d341fb6c9d42debcdd38d82a0a545c?tpId=182&tqId=34902&ru=/exam/oj
public class code2 {
    // 1 -2 3 10 -4 7 2 -5
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] arr = new int[n];

        for (int i = 0;i < n;i++) {
            arr[i] = scanner.nextInt();
        }

        int max = arr[0];
        int sum = arr[0];
        for (int i = 1;i < n;i++) {
            sum = Math.max(sum + arr[i],arr[i]);
            if(sum > max) {
                max = sum;
            }
        }
        System.out.println(max);
    }
}
